package com.vgemv.jsutilitysdk.Menu.JsMenuView.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemModelDefault;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;

public class JsListItemView extends JsMenuItemView {
        public TextView mtv_index;
        public TextView mtv_title;
        public TextView mtv_description;
        public JsListItemView(Context context) {
            super(context);

            //基础是一个LinearLayout
            LinearLayout linearLayoutH = new LinearLayout(context);
            addView(linearLayoutH);

            mtv_index = new TextView(context);
            mtv_index.setLayoutParams(new ViewGroup.LayoutParams(100, ViewGroup.LayoutParams.MATCH_PARENT));
            mtv_index.setBackgroundColor(Color.argb(255,200,100,100));
            mtv_index.setGravity(Gravity.CENTER);

            LinearLayout linearLayoutV = new LinearLayout(context);
            //设置线性布局的方向
            linearLayoutV.setOrientation(LinearLayout.VERTICAL);
            mtv_title = new TextView(context);
            mtv_title.setTextSize(18);
            //android中为textview动态设置字体为粗体
            mtv_title.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));

            mtv_description = new TextView(context);
            LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT, 1.0f);
            mtv_description.setLayoutParams(linearLayoutParams);

            linearLayoutH.addView(mtv_index);
            linearLayoutV.addView(mtv_title);
            linearLayoutV.addView(mtv_description);
            linearLayoutH.addView(linearLayoutV);

            //view自己的布局不能在自己的构造函数中设置...一般都是在创建一个view之后,再设置.
//            ViewGroup.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
//            linearLayoutH.setLayoutParams(lp);

        }

    @Override
    public void customSetVm(Context context, JsMenuItemVm itemVm) {
            JsListItemVm vm = (JsListItemVm)itemVm;
        JsMenuItemModelDefault model = (JsMenuItemModelDefault)vm.currentModel();
        mtv_index.setText(String.format("%02d",vm.index));
        mtv_title.setText(model.mStr_title);
        mtv_description.setText(model.mStr_detail);
    }
}